using UnityEngine;
using UnityEngine.UI;
using DG;
using DG.Tweening;
using System;
using DragonBones;
using System.Collections;
namespace Kayac.HyperCasual
{
	public class LevelComplete : MonoBehaviour
	{
		[SerializeField]
		private bool autoUpdate;

		[SerializeField]
		private bool animationEnabled;

		[SerializeField]
		private float mainScaleSpeed;

		[SerializeField]
		private float backScaleSpeed;

		[SerializeField]
		private float backMaxScale;

		[SerializeField]
		private float backAlphaDecaySpeed;

		[SerializeField]
		private Image back;

		[SerializeField]
		private Image main;
		[SerializeField]
		private UnityArmatureComponent unityArmature;
		public Text text;
		public Image mask;
		public Action step1;
		public Action step2;
		public void ShowPanel()
		{
			back.gameObject.SetActive(true);
			main.gameObject.SetActive(true);
			text.text = "第" + (Main.Instance.saveData.LevelIndex + 1) + "关";
			Sequence sequence = DOTween.Sequence();
			sequence.Append(back.transform.DOScale(Vector3.one * 1.00f, 0.30f));
			sequence.Join(back.DOFade(1f, 0.1f).SetEase(Ease.InQuad));
			sequence.Append(back.transform.DOScale(Vector3.one * 0.9f, 0.30f));
			sequence.Join(back.DOFade(0f, 0.1f).SetEase(Ease.OutQuad));
			//sequence.AppendInterval(1f);
			sequence.AppendCallback(() =>
			{
				StartCoroutine(NextStep());
			});
			// sequence.AppendCallback(() => step2());
			// sequence.Append(text.transform.DOMoveY(text.transform.position.y - 400f, 1.5f).SetEase(Ease.OutQuad));
			// sequence.Append(text.transform.DOMoveY(text.transform.position.y, 1.5f).SetEase(Ease.InQuad));
			// sequence.OnComplete(() =>
			// {
			// 	gameObject.SetActive(false);
			// 	UIManager.Instance.CreateOrOpen(PanelId.MainMenu);
			// });
			// text.text = "第" + (Main.Instance.saveData.LevelIndex + 1) + "关";
			// unityArmature.gameObject.SetActive(true);
			// unityArmature.animation.Play("newAnimation", 1);
			// unityArmature.AddDBEventListener(EventObject.COMPLETE, OnAnimationComplete);
		}
		// private void OnAnimationComplete(string type, EventObject eventObject)
		// {
		// 	if (eventObject.animationState.name == "newAnimation")
		// 	{
		// 		StartCoroutine(NextStep());
		// 	}
		// }
		IEnumerator NextStep()
		{
			yield return new WaitForSeconds(1f);
			//unityArmature.gameObject.SetActive(false);
			gameObject.SetActive(false);
			UIManager.Instance.CreateOrOpen(PanelId.LevelComplete);
		}
	}
}
